<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Drugs_model extends CI_Model {
	
	function add_mdc() {
		$new_mdc_insert_data = array(
			'mdc_name' => $this->input->post('mdc_name'),
			'mdc_type' => $this->input->post('mdc_type'),
			'mdc_amount' => $this->input->post('mdc_amount'),
			'mdc_cost' => $this->input->post('mdc_cost'),
			
			'mdc_expire' => $this->input->post('mdc_expire'),
			'price1' => $this->input->post('price1'),
			'price2' => $this->input->post('price2'),
			'price3' => $this->input->post('price3')
		);
		
		$insert = $this->db->insert('inventories', $new_mdc_insert_data);
		return $insert;
	}
	
	function insert_mdc($data) {
	
		$this->db->insert('inventories',$data);	
	}
	
	function select_all() {
	
		$this->db->select('*');
		$this->db->from('inventories');
		$this->db->join('mdctype','inventories.mdctype_id = mdctype.mdctype_id','left');
		$query = $this -> db -> get();
		return $query->result_array();
	}
	
	function _getAll(){
	
		$result = $this->db->get('inventories')->result();
		return $result;
	}
	
	function _getDetail($mdc_name){
	
		$result = $this->db->where('mdc_name', $mdc_name)->get('inventories')->row();
		return $result;
	}
	
	function search($keyword) {
		
		$this->db->like('mdc_name',$keyword);
		
		$query = $this->db->get('inventories');
		return $query->result_array();
	}
	
	function select_mdc_id($mdc_id) {
		
		$this->db->select('*');
		$this->db->from('inventories');
		$this->db->where('mdc_id',$mdc_id);
		$qurey = $this->db->get();
		return $qurey->row_array();
	}
	
	function select_mdctype_id($mdctype_id) {
	
			$this->db->select('*');
			$this->db->from('inventories');
			$this->db->where('inventories.mdctype_id',$mdctype_id);
			$this->db->join('mdctype', 'inventories.mdctypr_id = inventories.mdctype_id','left');
			$qurey = $this->db->get();	
			return $qurey->result_array();
	}
	
	function search_key($keyword) {
			
			$sql = "SELECT * FROM `inventories` LEFT JOIN mdctype ON  inventories.mdctype_id = mdctype.mdctype_id WHERE inventories.mdc_name like '%".$keyword."%' ";
			$query = $this->db->query($sql);
	       
		   if($query -> num_rows() >= 1)
		   		{
		     		return $query->result_array();
		   		}
		  		 else
		  		 {
		     		return false;
		  		 }
		   // return $query->result_array();
	}
	
	function delete($id)
	{
		$this->db->where('mdc_id',$id);
		$this->db->delete('inventories'); 
	}
	
}